<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        function roll(node) {
            if (node.next) {
                var nodenew = roll(node.next);
                node.next.next=node;
                node.next=null;   
                return nodenew
            } else {
                return node;
            }
        }
        function ListNode(value, node) {
            this.val = value;
            this.next = node;
        }
        var a = new ListNode(5, null);
        var b = new ListNode(4, a);
        var c = new ListNode(3, b);
        var d = new ListNode(2, c);
        var e = new ListNode(1, d);
        var ttt = roll(e);
        console.log(ttt);
    </script>
</body>
</html>